package com.xbdun.dao.bmp.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import com.xbdun.dao.bmp.entity.XbdunOrgInviteCodeDo;

//邀请码
@Mapper
public interface OrgInviteCodeMapper {
	/**
	 * 新增
	 * @param XbdunOrgInviteCodeDo 企业员工注册邀请码
	 */
	@Insert("INSERT INTO xbdun_org_invite_code(userCode,orgCode,idCard,inviteCode,createTime,endTime,platType) VALUES(#{a.userCode},#{a.orgCode},#{a.idCard},#{a.inviteCode},#{a.createTime},#{a.endTime},#{a.platType})")
	@SelectKey(statement="SELECT LAST_INSERT_ID() AS ID", before = false, keyProperty = "a.id", resultType = Long.class)
	public Long addXbdunOrgInviteCode(@Param("a")XbdunOrgInviteCodeDo xbdunOrgInviteCodeDo);
	
	/**
	 * 根据主键获取对象
	 * @return
	 */
	@Select("SELECT * FROM xbdun_org_invite_code where idCard=#{idCard} AND inviteCode = #{inviteCode}")
	public XbdunOrgInviteCodeDo getXbdunOrgInviteCodeById(@Param("idCard")String idCard,@Param("inviteCode")String inviteCode);
	@Select("SELECT * FROM xbdun_org_invite_code where orgCode=#{orgCode} AND inviteCode = #{inviteCode}")
	public XbdunOrgInviteCodeDo getXbdunOrgInviteCodeByOrg(@Param("orgCode")long qrOrgCode,@Param("inviteCode")String inviteCode);
	//删除邀请码
	@Delete("DELETE FROM xbdun_org_invite_code WHERE id=#{id}")
	public int deleteInviteCode(@Param("id")long id);

	//删除邀请码
	@Delete("DELETE FROM xbdun_org_invite_code WHERE userCode=#{userCode} AND orgCode=#{orgCode}")
	public void deleteInviteCodeByUserIdAndOrgCode(@Param("userCode")long userCode, @Param("orgCode")long orgCode);
	
}
